﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.Serialization;

namespace ServerSandboxie
{


    public abstract class DrawObject
    {
        public DrawObject()
        {
        }
        //是否选择了该对象
        public bool Selected { get; set; }
        // 画笔颜色
        public Color PenColor { get; set; }
        //画笔宽度
        public int PenWidth { get; set; }
        // 绘制图像的ID
        public int ID { get; set; }
        public abstract void Draw(Graphics g);  //画图
        public abstract DrawObject Clone(); //克隆

        //扩充类需要实现的属性或方法
        public abstract int HandleCount { get; }  //句柄数
        public abstract Point GetHandle(int handleNumber); //获取句柄所在的点
        public abstract Rectangle GetHandleRectangle(int handleNumber);//获取句柄的实体矩形
        public abstract void DrawTracker(Graphics g); //绘制句柄

        public abstract int HitHandleTest(Point point);//判断是否选中该对象及句柄
        public abstract bool PointInObject(Point point);//判断该点是否在对象内
        public abstract Cursor GetHandleCursor(int handleNumber);//根据句柄获取光标类型
        public abstract bool IntersectsWith(Rectangle rectangle);//判断是否相交
        public abstract void Move(int deltaX, int deltaY);//移动对象
        public abstract void MoveHandleTo(Point point, int handleNumber);//移动句柄
       
        //[OnSerializing]   //OnSerializing特性表示序列化时自动调用自定义的方法SerializdInfo
        public virtual void LoadSerializdInfo(SerializationInfo info, int objectIndex)
        {
            info.AddValue("penColor" + objectIndex, PenColor, typeof(Color));
            info.AddValue("penWidth"+objectIndex,PenWidth);
            info.AddValue("ID"+objectIndex,ID);
        }
        //[OnDeserializing]   //OnDeserializing特性表示反序列化时自动调用自定义的方法DeserializdInfo
        /// <summary>反序列化</summary>
        public virtual void SaveDeserializdInfo(SerializationInfo info, int objectIndex)
        {          
            PenColor = (Color)info.GetValue("penColor" + objectIndex, typeof(Color));
            PenWidth = info.GetInt32("penWidth" + objectIndex);
            ID = info.GetInt32("ID" + objectIndex);
        }


    }
}
